package cn.tedu.yl.professional.service.impl;

import cn.tedu.yl.base.response.PageData;
import cn.tedu.yl.professional.mapper.ProfessionalMapper;
import cn.tedu.yl.professional.pojo.dto.ProfessionalDelParam;
import cn.tedu.yl.professional.pojo.dto.ProfessionalQuery;
import cn.tedu.yl.professional.pojo.dto.ProfessionalSaveParam;
import cn.tedu.yl.professional.pojo.entity.Professional;
import cn.tedu.yl.professional.pojo.vo.ProfessionalVO;
import cn.tedu.yl.professional.service.ProfessionalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class ProfessionalServiceImpl implements ProfessionalService {
    @Autowired
     private ProfessionalMapper professionalMapper;

    //查询列表数据
    @Override
    public PageData selectList(ProfessionalQuery professionalQuery) {
        log.info("获取职称管理列表请求参数:{}",professionalQuery);
        PageData pageData = new PageData();
        List<ProfessionalVO> list = professionalMapper.selectList(professionalQuery);
        int total = professionalMapper.selectTotal(professionalQuery);
        pageData.setList(list);
        pageData.setTotal(total);
        return pageData;
    }


    //根据id查询详情
    @Override
    public ProfessionalVO selectDetailById(Integer id) {
        log.info("获取职称管理详情id:{}",id);
        ProfessionalVO professionalVO = professionalMapper.selectDetailById(id);
        return professionalVO;
    }


    //保存职称管理数据
    @Override
    public void save(ProfessionalSaveParam professionalSaveParam) {
        log.info("获取职称保存参数:{}",professionalSaveParam);
        Professional professional = new Professional();
        BeanUtils.copyProperties(professionalSaveParam,professional);

        if(professionalSaveParam.getId() == null){
            //新增
            professional.setCreateTime(new Date());
            professionalMapper.insert(professional);
        } else {
            //修改
            professional.setUpdateTime(new Date());
            professionalMapper.update(professional);
        }

    }


    //批量删除功能
    @Override
    public void delete(ProfessionalDelParam pofessionalDelParam) {
        log.info("获取删除的id数组:{}",pofessionalDelParam);
        List<Integer> ids = pofessionalDelParam.getArrIds();
        professionalMapper.delete(ids);
    }


}


































